package com.cdtu.outtake.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cdtu.outtake.domain.Product;
import com.cdtu.outtake.domain.Shop;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author : shl
 * @Date 2024/3/20 19:41
 */
public interface ProductMapper extends BaseMapper<Product> {
    @Select("""
            select shop.id, shop.name, offline_pick_up, phone, shop.picture, shop.sales, shop.score, takeaway, address, dine_in, moa, school_id
            from shop, category, product
            where shop.id = category.shop_id
            and category.id = product.category_id
            and (category.name like #{keyword} or product.name like #{keyword})
            and shop.school_id = #{schoolId}
            group by shop.id, shop.name, offline_pick_up, phone, shop.picture, shop.sales, shop.score, takeaway, address, dine_in, moa, school_id
            """)
    List<Shop> getShopBySchoolIdAndKeyword(Long schoolId, String keyword);

    @Select("""
            select shop.id, shop.name, offline_pick_up, phone, shop.picture, shop.sales, shop.score, takeaway, address, dine_in, moa, school_id
            from shop, category, product
            where shop.id = category.shop_id
            and category.id = product.category_id
            and (category.name like CONCAT('%',#{keyWord},'%')
            or product.name like CONCAT('%',#{keyWord},'%'))
            group by shop.id, shop.name, offline_pick_up, phone, shop.picture, shop.sales, shop.score, takeaway, address, dine_in, moa, school_id
            """)
    List<Shop> getShopByKeyword(String keyword);
}
